package camid.util.monitoring;


public class NodeEvaluator {

	private MetricEvaluator responseTimeEvaluator;
	
	private MetricEvaluator cpuEvaluator;
	
	private MetricEvaluator memEvaluator;
	
	private MetricEvaluator numberOfObjectsEvaluator;
	
	
	
	public Double feedMetric(NodeMetrics nodeMetrics) {
		
		double rtCost = responseTimeEvaluator.evaluateCostFromMetric(nodeMetrics.getNodeResponseTime());
		double cpuCost = cpuEvaluator.evaluateCostFromMetric(nodeMetrics.getCpuUsage());
		double memCost = memEvaluator.evaluateCostFromMetric(nodeMetrics.getMemoryUsage());
		double nobjCost = numberOfObjectsEvaluator.evaluateCostFromMetric(nodeMetrics.getNumberOfObjects());
		
		
		double weightTotal = responseTimeEvaluator.getWeight()
							  + cpuEvaluator.getWeight()
							  + memEvaluator.getWeight()
							  + numberOfObjectsEvaluator.getWeight();
		
		double nodeCost = (rtCost + cpuCost + memCost + nobjCost) / weightTotal;
		
		return nodeCost;
	}

	public void setNumberOfObjectsWeight(Double numObjectsWeight) 
	{
		numberOfObjectsEvaluator = new MetricEvaluator("NO", numObjectsWeight);	
	}

	public void setResponseTimeWeight(Double responseTimeWeight) 
	{
		responseTimeEvaluator = new MetricEvaluator("RT", responseTimeWeight);	
	}

	public void setCPUWeight(Double cpuWeight) 
	{
		cpuEvaluator = new MetricEvaluator("CPU", cpuWeight, 0, 1);
	}
	
	public void setMemWeight(Double memWeight) 
	{
		memEvaluator = new MetricEvaluator("MEM", memWeight, 0, 100);
	}

	public double numberOfObjectsFromCost(double cost) 
	{	
		double nobj = numberOfObjectsEvaluator.evalateMetricFromCost(cost);
		return nobj;
	}

	

}
